import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yi_shop/components/order/index.dart';
import 'package:yi_shop/ui/keep_alive.dart';
import 'package:yi_shop/utils/styles.dart';
import 'package:yi_shop/utils/tools.dart';

class SystemOrderListController extends GetxController with GetSingleTickerProviderStateMixin {
  late TabController controller;
  List<String> tabs = ['全部', '待付款', '待收货', '已完成', '已取消'];

  @override
  void onInit() {
    controller = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    controller.dispose();
    super.onClose();
  }
}

class SystemOrderListPage extends GetView<SystemOrderListController> {
  const SystemOrderListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: ToolsUtils.builderLeading(),
        title: Text(
          '商城订单',
          style: StylesUtils.customTextStyle(
              fontSize: StylesUtils.fontSize18, fontWeight: FontWeight.w700),
        ),
        bottom: PreferredSize(
            preferredSize: const Size.fromHeight(40),
            child: Container(
              color: Colors.white,
              child: ToolsUtils.getClientTabBar(controller.tabs, controller.controller,
                  isScrollable: false, indicatorSize: TabBarIndicatorSize.tab),
            )),
      ),
      body: TabBarView(
        controller: controller.controller,
        children: [
          KeepAliveWrapperTabView(
            child: const OrderAllView(),
            callback: () {
              Get.put(() => OrderAllController());
            },
          ),
          KeepAliveWrapperTabView(
              child: const OrderPendingPaymentView(),
              callback: () {
                Get.put(OrderPendingPaymentController());
              }),
          KeepAliveWrapperTabView(
              child: const OrderWaitReceivedView(),
              callback: () {
                Get.put(OrderWaitReceivedController());
              }),
          KeepAliveWrapperTabView(
              child: const OrderCompletedView(),
              callback: () {
                Get.put(OrderCompletedController());
              }),
          KeepAliveWrapperTabView(
              child: const OrderCancelledView(),
              callback: () {
                Get.put(OrderCancelledController());
              }),
        ],
      ),
    );
  }
}
